<script type="text/javascript">
	function jiancha() {
		$("#jianchaitem").modal('open');
	}
	
	var itemlist = [];
	
	function delitem11(val) {
		$("#itemitem" + val + "").remove();
		itemlist[val] = undefined;
	}
	
	function iitemsure(){
		var name = $('#itemselect option:selected').text();
		var val = $('#itemselect option:selected').val();
		if (name != "") {
				if (itemlist[val] == undefined) {
					    itemlist[val] = name;
						$("#ckeck_info").append(
								"<tr id='itemitem"+val+"'><td>"
										+ name
										+ "</td>"
										+ "<td>"
										+ $("#iitemprice" + val + "").find("a")
												.html()
										+ "</td><td><button onclick='delitem11("
										+ val + ")'>删除</button></td></tr>");
				} else {
					$("#myalertbody").html("已有检查项目！");
					$("#my-alert").modal('open');
				}
		} else {
			$("#myalertbody").html("请选中检查项目！");
			$("#my-alert").modal('open');
		}
	}
	
	function itemcommit(){
		if($("#docccid").val()!=""&&$("#patttid").val()!=""){
		var iteml = [];
		$("#ckeck_info").find("tr").each(function(i) {
			var obj = new Object();
			obj.name = $(this).find("td:eq(0)").html();
			obj.docid = $("#docccid").val();
			obj.patient = $("#patttid").val();
			iteml[i] = obj;
		});
		$.post('${ctx}/main/jiancha', {
			"itemlist" : JSON.stringify(iteml)
		}, function(data) {
			if (data.success.success) {
				$("#myalertbody").html("开药成功！");
				$("#jianchaitem").modal('close');
				$("#my-alert").modal('open');
				$("#ckeck_info").html("");
				$("#docccid").val("");
				$("#patttid").val("");
			}else{
				$("#myalertbody").html(data.success.fail);
				$("#jianchaitem").modal('close');
			}
		}, 'json');
	}
		else{
			$("#myalertbody").html("信息不得为空！");
			$("#my-alert").modal('open');
		}
	}
</script>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="jianchaitem">
	<div class="am-modal-dialog" style="border-radius: 10px;width:500px">
		<div class="am-modal-hd">
			检查列表 <a href="javascript: void(0)" class="am-close am-close-spin"
				data-am-modal-close>&times;</a>
		</div>
		<div class="am-modal-bd">
			<div>
				<table border="0" class="am-table am-table-radius am-table-striped">
					<tr>
						<td><input placeholder="病人序列号" type="text" id="patttid" /></td>
						<td><input placeholder="医生ID" type="text" id="docccid" /></td>
						<td></td>
					</tr>
					<tr>
						<td><select id="itemselect" style="width:214px">
								<option></option> <#if item ??> <#list item as i>
								<option value="${i_index}">${i.item_name}</option> </#list>
								</#if>
						</select></td>
						<td><button onclick="iitemsure()" >确定</button></td>
					</tr>
				</table>

			</div>
			<div id="paitentinfo2" style="display:">
				<table
					class="am-table am-table-bordered am-table-radius am-table-striped">
					<thead>
						<tr>
							<th style="text-align: center">检查项目</th>
							<th style="text-align: center">价格</th>
							<th style="text-align: center">操作</th>
						</tr>
					</thead>
					<tbody id="ckeck_info">

					</tbody>
				</table>
			</div>
			<button onclick="itemcommit()" style="float: right;margin-bottom:10px">提交</button>
		</div>
	</div>
</div>